package hello;

import org.hibernate.Session;
import org.hibernate.Transaction;

import persistence.HibernateUtil;
import auction.chapter08.BidFormulaJoin;
import auction.chapter08.ItemFormulaJoin;

public class HelloWorldFormulaJoin
{
	
	
	public static void main(String[] args)throws Exception
	{
		
		Session s=HibernateUtil.getSessionFactory().openSession();
		Transaction tx=s.beginTransaction();
		
		
		
		ItemFormulaJoin i=new ItemFormulaJoin();
		i.setTitle("iiiii");
		
		BidFormulaJoin bid=new BidFormulaJoin();
		i.addBid(bid);
		i.setSuccessfulBid(bid);
		
		//s.save(i);
		//s.save(bid);
		
		tx.commit();
		s.close();
		
		
		
		Session s1=HibernateUtil.getSessionFactory().openSession();
		Transaction tx1=s1.beginTransaction();
		
		ItemFormulaJoin loadi=(ItemFormulaJoin)s1.load(ItemFormulaJoin.class, 4L);
		loadi.setSuccessfulBid(i.getSuccessfulBid());
		//out(loadi.getSuccessfulBid());
		
		tx1.commit();
		s1.close();
		
		
		
		//HibernateUtil.stat();
		HibernateUtil.shutdown();
	}
	
	public static void getParent(Class clazz)
	{
		Class parent=clazz.getSuperclass();
	  if(parent !=null)
	  {
			System.out.println("###"+parent.getName());
			getParent(parent);
		}
	}
	
	static void out(Object obj)
	{
		System.out.println("--->"+obj);
	}
}
